<?php
/**
 * Created by PhpStorm.
 * User: Charles
 * Date: 2017/10/11
 * Time: 12:22
 */

namespace App\Models;

use Illuminate\Support\Facades\Cache;

class SettingsCache
{
    const prefix = 'SETTINGS_';

    public static function get($key, $default = null)
    {
        $cacheKey = self::prefix . $key;
        if (Cache::has($cacheKey)) {
            return Cache::get($cacheKey);
        }
        $value = Settings::get($key);
        Cache::put($cacheKey, $value, env('CACHE_TIME_OUT', 1440));
        $value = $value ? $value : $default;
        return $value;
    }

    public static function set($key, $value)
    {
        Cache::put(self::prefix . $key, $value, env('CACHE_TIME_OUT', 1440));
    }

    public static function forget($key)
    {
        Cache::forget(self::prefix . $key);
    }
}